<?php

namespace common\models;

use Yii;
use yii\db\ActiveRecord; // 活动记录模型
use yii\filters\RateLimitInterface; // 速率限制接口
use yii\web\IdentityInterface; // 用户身份接口

/**
 * This is the model class for table "{{%user}}".
 *
 * @property int $id
 * @property int $country_code 国家代码
 * @property string $mobile 手机号
 * @property string $nickname 昵称
 * @property string $avatar 头像链接地址
 * @property string $password_hash 账号密码
 * @property string $password_salt 密码加密盐
 * @property string $access_token API登录令牌
 * @property string $access_token_expire API登录令牌有效时长
 * @property int $status 账号状态：-1已注销，0黑名单，10激活
 * @property string $created_at
 * @property string $updated_at
 */
class UserModel extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%user}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['country_code', 'mobile', 'access_token_expire', 'status'], 'integer'],
            [['password_hash', 'password_salt', 'access_token', 'created_at', 'updated_at'], 'required'],
            [['created_at', 'updated_at'], 'safe'],
            [['nickname', 'password_salt'], 'string', 'max' => 20],
            [['avatar'], 'string', 'max' => 255],
            [['password_hash'], 'string', 'max' => 72],
            [['access_token'], 'string', 'max' => 32],
            [['access_token'], 'unique'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'country_code' => '国家代码',
            'mobile' => '手机号',
            'nickname' => '昵称',
            'avatar' => '头像链接地址',
            'password_hash' => '账号密码',
            'password_salt' => '密码加密盐',
            'access_token' => 'API登录令牌',
            'access_token_expire' => 'API登录令牌有效时长',
            'status' => '账号状态：-1已注销，0黑名单，10激活',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
        ];
    }
}
